/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.advertisements_tag;

import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 *
 * @author Bach
 */
public class DiasableAdv {

    public static boolean setDisableAdv(String adv_Id,String imageId) {
        String up = "UPDATE [Matrimony].[dbo].[Advertisements]\n"
                + "   SET [Advertisement_Status] =0\n"
                + " WHERE Advertisement_Id=? ";
        boolean re = false;
        Connection con = null;
        PreparedStatement ps = null;
        try {
            con = Connect_DB.getConnection();
            con.setAutoCommit(false);
            ps = con.prepareStatement(up);
            ps.setString(1, adv_Id);

            int i = ps.executeUpdate();

            if (i > 0) {
                if (disableImage(imageId, con)) {
                    re = true;
                    con.commit();
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(null, null, ps, con);
        }
        return re;
    }

    private static boolean disableImage(String imageId, Connection conn) {

        boolean b = false;
        String sql = "UPDATE [Matrimony].[dbo].[Images]\n"
                + "   SET [Image_Status] = 0\n"
                + " WHERE [Image_Id]=?";
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setString(1, imageId);
            int i = ps.executeUpdate();
            if (i > 0) {
                b = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b;
    }
}
